import math
from collections import defaultdict

n = int(input())
nums = list(map(int, input().split()))
dic1 = defaultdict(int)  # 某二进制位为1 累加其下标
dic0 = defaultdict(int)  # 某二进制位为0
cnt1 = defaultdict(int)
cnt0 = defaultdict(int)
max_bit = int(math.log2(max(nums))) + 1
ans = 0
for bit in range(max_bit):
    for i, num in enumerate(nums):
        if num & (1 << bit):
            dic1[bit] += i
            cnt1[bit] += 1
            ans += (i * cnt0[bit] - dic0[bit]) * (1 << bit)
        else:
            dic0[bit] += i
            cnt0[bit] += 1
            ans += (i * cnt1[bit] - dic1[bit]) * (1 << bit)
print(ans)
